package com.ruoyi.web.controller.lh;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.LhGood;
import com.ruoyi.system.service.LhGoodService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author 何金岳
 * @Description TODO
 * @createTime 2024年04月08日15时53分12秒
 * @since 1.0.0
 */
@RestController
public class LhGoodController extends BaseController {

    @Autowired
    private LhGoodService lhGoodService;

    @PostMapping(value = "/lh/good/insertGood")
    public AjaxResult insertGood(LhGood lhGood){
        AjaxResult result=lhGoodService.insertLhGood(lhGood);
        return result;
    }

    @PostMapping(value = "/lh/good/pageList")
    public TableDataInfo pageList(LhGood lhGood){
        startPage();
        List<LhGood> list=lhGoodService.pagelist(lhGood);
        return getDataTable(list);
    }

    @PostMapping(value="/lh/good/addGood")
    public AjaxResult addGood(@Validated @RequestBody LhGood lhGood){
        AjaxResult ajaxResult=lhGoodService.insertLhGood(lhGood);
        return ajaxResult;
    }

    @PostMapping(value="/lh/good/updateGood")
    public AjaxResult updateGood(@Validated @RequestBody LhGood lhGood){
        AjaxResult ajaxResult=lhGoodService.updateGood(lhGood);
        return ajaxResult;
    }
    @DeleteMapping("/lh/good/deleteByIds/{goodIds}")
    public AjaxResult deleteByIds(@PathVariable Long[] goodIds){
        List<Long> idList= Arrays.asList(goodIds.clone());
        lhGoodService.deleteByIds(idList);
        return AjaxResult.success();
    }
    @GetMapping(value="/lh/good/getGoodById/{id}")
    public AjaxResult getGoodById(@PathVariable Long id){
        LhGood lhGood=lhGoodService.getGoodById(id);
        if(lhGood==null){
            return error("该商品信息不存在。");
        }
        return success(lhGood);
    }
}
